package http_proxy_middleware

import (
	"strings"

	"gin-gateway/core/utils"
	"github.com/gin-gonic/gin"
)

// HTTPStripUrLMiddleware URL路径去除指定字符串。如去除接入前缀
//http://127.0.0.1:8080/test_http_string/abbb
//http://127.0.0.1:2004/abbb
func HTTPStripUrLMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		serviceDetail := GetServiceDetail(c)
		if serviceDetail.HTTPRule.RuleType == utils.HTTPRuleTypePrefixURL && serviceDetail.HTTPRule.NeedStripUri == 1 {
			c.Request.URL.Path = strings.Replace(c.Request.URL.Path, serviceDetail.HTTPRule.Rule, "", 1)
			//fmt.Println("c.Request.URL.Path",c.Request.URL.Path)
		}
		c.Next()
	}
}
